<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="../style/fjol_style.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../style/xol_style.css"/>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav newbgRed">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left">
		    	<!--<em class="f08">个人中心</em>-->
		    </a>
		    <h1 class="mui-title">登录</h1>
		</header>
		<div class="mui-content">
			<div class="mui-segmented-control m10 mt10">
				<a class="mui-control-item mui-active" id="loginDiv1">账户密码</a>
				<a class="mui-control-item" id="loginDiv2">短信验证码</a>
			</div>
			<div class="mt10" id="loginDivcon">
				<form>
					<div class="mui-input-row m10">

						<input type="text" id="name" class="mui-input-clear" placeholder="请输入手机号">
					</div>
					<div class="mui-input-row rel m10">

						<input type="password" id="passwords" class="" placeholder="请输入密码">
						<a class="abs f08" id="getYanzhengma" style="top: 10px; right: 10px; z-index: 3;">忘记密码?</a>
					</div>
				</form>
			</div>
			

			<div class="m10">
				<button type="button" id="confirm" class="mui-btn newbgRed colorWhite borderRadius6 mui-btn-block">登录</button>
			</div>
			<div align="right" class="pt10 pb10" id="toRegist">
				<span class="mui-badge mui-badge-primary mui-badge-inverted">
		    		没有账号？立即注册
		    		<span class="mui-icon mui-icon-arrowthinright vm"></span>
				</span>
			</div>
			
			<div class="fixed" style="bottom: 0; left: 0; right: 0; line-height: 30px;">
				<p class="mui-text-center f08">注册/登录即代表同意《鑫在线用户使用协议》</p>
			</div>
			<script src="../js/mui.min.js"></script>
			<script src="../js/common.util.js"></script>
			<script language='javascript' src='../js/md5.js'></script>
			<script src="../js/network.js"></script>
			<script src="../js/xzx.open.js"></script>
			<script type="text/javascript">
				mui.init();
				mui.plusReady(function(){
					
				//转去注册页面
				document.querySelector('#toRegist').addEventListener('tap', function() {
					openWindowWithPage('regist',{
						pageTip:'beUser'
					})
					
				});
				var _type = 1;
				mui('.mui-segmented-control').on('tap','a',function(){
//					console.log(this.getAttribute('id'));
					var loginStyle = this.getAttribute('id');
					if(loginStyle == 'loginDiv1'){	//账户密码方式登录
						_type = 1;
						document.querySelector('#passwords').placeholder = '请输入密码';
						document.querySelector('#getYanzhengma').innerHTML = '忘记密码?';
					}else{		//短信验证码登录
						_type = 2;	
						document.querySelector('#passwords').placeholder = '请输入验证码';
						document.querySelector('#getYanzhengma').innerHTML = '获取验证码';
					}
				});
				
				//登录
				document.querySelector('#confirm').addEventListener('tap', function() {
//					console.log(_type);
					var mobile = document.querySelector('#name').value;
					var password = document.querySelector('#passwords').value;
					var param = [{		//密码登录param
						key: 'mobile',
						value: mobile
					}, {
						key: 'password',
						value: hex_md5(password).toUpperCase()
					}, {
						key: 'userType',
						value: 1
					}];
					var param2 = [{		//验证码登录param
						key: 'mobile',
						value: mobile
					}, {
						key: 'code',
						value: password
					}, {
						key: 'userType',
						value: 1
					}
					];
					if(_type == 1){		//密码方式
						var _url = 'user/login.json';
						loginFn(_url,param);
					}else{				//验证码方式
						var _url = 'user/login-by-code.json';
						loginFn(_url,param2);
					}

					
				});
				
				//获取验证码
				document.querySelector('#getYanzhengma').addEventListener('tap',function(){
					var mobile = document.querySelector('#name').value;
					
					if(_type == 2){
						if(mobile.length == 0) {
							mui.toast('请输入手机号');
							return;
						}
						if(!common.validateMobile(mobile)) {
							mui.toast('请输入正确的手机号');
							return;
						}
						var paramCode = [{
							key:'mobile',
							value:mobile
						}]
						fjNetwork.get('user/mobileCode.json',paramCode,function(data){
							mui.toast(data.msg);
//							console.log(mobile+','+JSON.stringify(data));
							
						}, function(message) {
							//失败
							mui.toast(message);
						});
					}else{		//忘记密码
//						console.log(_type);
						openWindowWithPage('regist',{
							pageTip:'forgetPassword'
						});
					}
//				console.log(plus.push.getClientInfo().clientid);
				});
				
				});	//plusready()结束
				
				function loginFn(url,param){
					var wv = plus.webview.currentWebview();
					var parentId = wv.parentId;
//					console.log(parentId);
					var net = fjNetwork;
					var clientId;
					net.post(url, param, function(data) {
						//成功
						mui.toast(data.msg);
						var userInfo = data.userLoginInfo.user;
						clientId = data.client.id;
						userInfo.clientId = clientId;
						common.myStorage.setItem('userInfo', userInfo);
						common.myStorage.setItem('loginToken', data.userLoginInfo.loginToken);
						common.myStorage.setItem('userId', data.userLoginInfo.userId);
//						var personPage = plus.webview.getWebviewById('my_page');
						var personPage = plus.webview.currentWebview().opener();
						mui.fire(personPage,'refreshUserInfo');
						
//						var wobj = plus.webview.getWebviewById(parentId);
						mui.fire(wobj,'gobackDetail');	//楼盘户型详情
						var wobj = plus.webview.currentWebview().opener();
						wobj.reload(true);		//页面刷新
						
//						plus.webview.getWebviewById('my_page').reload();
						
       					mui.back();
						
					}, function(message) {
						//失败
						mui.toast(message);
					});
				}
			</script>
	</body>

</html>